﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Net;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSearchTour_Click(object sender, ImageClickEventArgs e)
    {
        string strParam;

        string from = txtFrom.Text;
        string to = txtTo.Text;
        DateTime departDate = new DateTime(txtYear.Text == "" ? 1 : int.Parse(txtYear.Text), txtMonth.Text == "" ? 1 : int.Parse(txtMonth.Text),txtDay.Text==""?1: int.Parse(txtDay.Text));
        DateTime returnDate = new DateTime(txtYearr.Text == "" ? 1 : int.Parse(txtYearr.Text), txtMonthr.Text == "" ? 1 : int.Parse(txtMonthr.Text), txtDayr.Text == "" ? 1 : int.Parse(txtDayr.Text));

        strParam = from + "-" + to + "-" + Util.ConvertDateToString(departDate) + "-" + Util.ConvertDateToString(returnDate);

        Response.Redirect("Tours.aspx?param="+strParam);
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string strRegEmail = @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
        Regex reLenient = new Regex(strRegEmail);

        if (reLenient.IsMatch(txtEmail.Text))
        {
            //Get new tour
            StringBuilder strContent = new StringBuilder();
            string newLine = "\n\r";
            strContent.Append("<b>LIST NEW TOURS</b>" + newLine);
            DataTable dt = TourManagement.GetAllTour().Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                strContent.Append(row["NO"].ToString() + ". ");
                strContent.Append(row[TourManagement.TOURNAME].ToString() + newLine);
                strContent.Append("Price: $" + row[TourManagement.PRICE].ToString() + newLine);
                strContent.Append("Hotel: " + row[HotelManagement.HOTELNAME].ToString() + newLine);
                strContent.Append("Itinerary: " + row[TourManagement.ITINERARY].ToString() + newLine);
                strContent.Append("Plan: " + row[TourManagement.PLANTOUR].ToString() + newLine);
            }

            if (Util.SendEmail("vietnam.tour.201107@gmail.com", txtEmail.Text, "New tours", strContent.ToString()))
                ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Check email for new tour, please!');</script>");
        }
        else
            ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script> alert('Email invalid!');</script>");
    }


}